package com.rc.evcharger.common.type;


import com.rc.evcharger.common.annotation.ByteLength;
import com.rc.evcharger.common.constant.SocketConstant;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * 后台控制充电数据格式
 * @author kb
 */
public class ElecControl extends BaseType implements DataType {
    String measuringPoint; // 测量点号
    String permisson; // 权限等级
    String password; // 密码
    // 以下是数据域
    String storage = "40 88"; // 寄存器 默认 88 40（低位在前）
    String startStatus; // 启动状态 2：充电开始3：停止充电
    String cardNo; // 交易卡号
    String gunNo; // 枪号

    @ByteLength(length = 4, decimal = 2) // 放大倍率
            BigDecimal balance; // 卡内余额

    // private int length; //数据长度

    public ElecControl() {
        super();
    }

    /**
     * 后台控制充电启停中，测量点0,1,2,3对应帧结构中的测量点号1,2,4,8，枪号0,1,2,3(珠海生产的)
     * 测量点号就是枪号(深圳生产的)
     * @param permisson
     * @param password
     * @param startStatus
     * @param cardNo
     * @param gunNo
     * @param balance
     */
    public ElecControl(String permisson, String password, String startStatus, String cardNo, String gunNo,
                       BigDecimal balance, String source) {
        super();

        StringBuffer sb = new StringBuffer();
        if (SocketConstant.SOURCE_ZHUHAI.equalsIgnoreCase(source)) {
            sb.append("0").append((int) Math.pow(2, Integer.parseInt(gunNo)));
        } else {
            if (gunNo.length() < 2)
                sb.append("0");
            sb.append(gunNo);
        }
        this.measuringPoint = sb.toString();
        this.permisson = permisson;
        this.password = password;
        this.startStatus = "0" + startStatus;
        this.cardNo = cardNo;
        this.gunNo = "0" + gunNo;
        this.balance = balance;
    }

    public String getMeasuringPoint() {
        return measuringPoint;
    }

    public void setMeasuringPoint(String measuringPoint) {
        this.measuringPoint = measuringPoint;
    }

    public String getPermisson() {
        return permisson;
    }

    public void setPermisson(String permisson) {
        this.permisson = permisson;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getStorage() {
        return storage;
    }

    public void setStorage(String storage) {
        this.storage = storage;
    }

    public String getStartStatus() {
        return startStatus;
    }

    public void setStartStatus(String startStatus) {
        this.startStatus = startStatus;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public String getGunNo() {
        return gunNo;
    }

    public void setGumNo(String gunNo) {
        this.gunNo = gunNo;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    @Override
    public Object getValue(String dataStr) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        return false;
    }

    public void setGunNo(String gunNo) {
        this.gunNo = gunNo;
    }

}
